<?php require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($_SERVER['DOCUMENT_ROOT']."/Modules/MGK20XF5/moduleconf.php");
MYDCONN(); ?>
<table width="100%"  border="0" cellpadding="5" cellspacing="0">
  <tr>
    <td width="180" valign="top">
	  <table width="180"  border="0" cellpadding="3" cellspacing="1">
        <tr bgcolor="#ACB1CC">
          <td rowspan="6" bgcolor="#CED7DE"> <img 

src="<?php echo $GLOBALS['GFX'];?>CentrodeCustos/Docs.png" border="0" alt="Economato"> </td>
          <td>Documentação</td>
        </tr>
        <tr bgcolor="#F2F2F2">
          <td height="8"><a href="index.php">Novo documento</a></td>
        </tr>
        <tr bgcolor="#F2F2F2">
          <td height="8"><a href="properties.php">Documentos</a></td>
        </tr>
        <?php
    $QNav = "SELECT hnav_areas.ref,
						hnav_areas.name
					FROM hnav_areas
					WHERE hnav_areas.Module = 17
				ORDER BY name";
	$Nav = $GLOBALS['CONN']->db_array($QNav); 
	for ($f = 1; $f <= $Nav[0]; $f++) { ?>
        <tr bgcolor="#F8F8F8">
          <td><a href="?jB=<?php echo $Nav[$f]['ref'];?>">
            <?php echo $Nav[$f]['name'];?>
          </a></td>
        </tr>
        <?php } ?>
      </table>
    <td width="100%" valign="top"><table width="100%"  border="0" cellpadding="3" 

cellspacing="1">
  <form action="?jB=<?php echo $_GET['jB'];?>" method="get" name="getContracts" runat="server">
    <tr bgcolor="#99CCCC">
      <td bgcolor="#ACB1CC" colspan="9">Documentos</td>
    </tr>
  </form>
  <?php
  if (!isset($_GET['Iv'])) { 
  
  echo '<tr bgcolor="#F2F2F2">
  	<td width="5%">N�mero</td>
  	<td width="5%">Tipo</td>
    <td width="25%">T�tulo</td>
    <td width="5%">Data</td>
    <td width="5%">Autor</td>
    <td width="5%">Respons�vel</td>
  </tr>';

    $CResults = "SELECT 
					a.Ref,
					a.Title,
					a.Body,
					a.Time,
					a.Author,
					a.DocRefer,
					x.NAME AS Attrib,
					hcdc_types.NAME AS TYPE
				FROM doccenter_document AS a
				INNER JOIN hcdc_types ON hcdc_types.REF = a.TYPE
				INNER JOIN main_usersgroups AS x ON x.REF = a.Attrib";
	$Results = $GLOBALS['CONN']->db_array($CResults); 
	for ($f = 1; $f <= $Results[0]; $f++) { 
	
		echo'<tr bgcolor="#D3D6E4">
		<td><a href="?Iv='.$Results[$f]['Ref'].'">'.$Results[$f]['DocRefer'].'</a></td>
		<td>'.$Results[$f]['TYPE'].'</td>
		<td>'.$Results[$f]['Title'].'</td>
		<td>'.$Results[$f]['Time'].'</td>
		<td>'.$Results[$f]['Author'].'</td>
		<td>'.$Results[$f]['Attrib'].'</td>
		</tr>';
   }  
   } else {
	echo '<tr bgcolor="#D3D6E4">
		<td colspan="5">^ Listagem de Documentos Minimizada | <a href="?jB=4">Maximizar 

(+)</a></td>
		</tr>'; ?>
<table width="100%"  border="0" cellspacing="1" cellpadding="3">
	<form action="index.php" method="post">
          <?php
    $CResults = "SELECT 
					a.Ref,
					a.Title,
					a.Body,
					a.Time,
					YEAR(a.Time) AS Y,
					a.Author,
					a.DocRefer,
					x.NAME AS Attrib,
					hcdc_types.NAME AS TYPE
				FROM doccenter_document AS a
				INNER JOIN hcdc_types ON hcdc_types.REF = a.TYPE
				INNER JOIN main_usersgroups AS x ON x.REF = a.Attrib
				WHERE a.Ref = {$_GET['Iv']}";
	$Results = $GLOBALS['CONN']->db_array($CResults); 
	for ($f = 1; $f <= $Results[0]; $f++) { 
	mn_field('hidden','ED','DOCX',$Results[$f]['Ref'],'','','False','');
	?>
          <tr bgcolor="#ACB1CC">
            <td colspan="2">Propriedades do Documento <input value="Editar" name="Dav" type="submit"></td>
          </tr>
          <tr bgcolor="#F2F2F2">
            <td colspan="2"><?php echo $Results[$f]['TYPE'];?>: 

<?php echo $Results[$f]['DocRefer'];?>/<?php echo $Results[$f]['Y'];?></td>
          </tr>
          <tr bgcolor="#F2F2F2">
            <td width="21%">Título:</td>
            <td><?php echo $Results[$f]['Title'];?></td>
          </tr>
          <tr bgcolor="#F2F2F2">
            <td>Texto:</td>
            <td><?php echo nl2br($Results[$f]['Body']);?></td>
          </tr>
          <tr bgcolor="#F2F2F2">
            <td>Responsável: </td>
            <td><?php echo $Results[$f]['Attrib'];?></td>
          </tr>
          <tr bgcolor="#FBFBFB">
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr bgcolor="#F2F2F2">
            <td colspan="2">Assinado.</td>
          </tr>
          <tr bgcolor="#FBFBFB">
            <td colspan="2"><?php echo nl2br($Results[$f]['Author']);?></td>
          </tr>
          <tr bgcolor="#FBFBFB">
            <td colspan="2">Leituras: <?php 
			$Res = $GLOBALS['CONN']->db_array("SELECT 
					main_users.name,
					main_users.username
				FROM doccenter_userreads AS a
				INNER JOIN main_users ON main_users.ref = a.USER
				WHERE a.DOC = {$Results[$f]['Ref']}"); 
	for ($g = 1; $g <= $Res[0]; $g++) { 
	print $Res[$g]['username'].' / '.$Res[$g]['name'].'<br>';
	}?></td>
          </tr>
		  </form>
          <?php } ?>
      </table> 

	<?php
  }?>
</table>
  </tr>
</table>